package com.cloudmusic.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cloudmusic.dao.AddToSongListMapper;
import com.cloudmusic.entity.Music;
import com.cloudmusic.service.AddToSongListService;

@Service
@Transactional
public class AddToSongListServiceImpl implements AddToSongListService {
	
	@Autowired
	AddToSongListMapper addToSongListMapper;

	public void addToLikesSongList(Object uid,List<Music> listSelected) {
		String lid = addToSongListMapper.selectLikelid(uid);
		for(Music attribute : listSelected) {
			if(addToSongListMapper.isExist(lid,attribute.getSid())==null) {
			    addToSongListMapper.insertToLikeSongList(lid,attribute.getSid());
			}
		}
	}
	
	public void addToCollectsSongList(Object uid,List<Music> listSelected) {
		String lid = addToSongListMapper.selectCollectlid(uid);
		for(Music attribute : listSelected) {
			if(addToSongListMapper.isExist(lid,attribute.getSid())==null) {
			    addToSongListMapper.insertToCollectSongList(lid,attribute.getSid());
			}
		}
	}
	
	public void addToLikeSongList(Object uid,String songid) {
		String lid = addToSongListMapper.selectLikelid(uid);
		if(addToSongListMapper.isExist(lid,songid)==null) {
		    addToSongListMapper.insertToLikeSongList(lid,songid);
		}
	}
	
	public void addToCollectSongList(Object uid,String songid) {
		String lid = addToSongListMapper.selectCollectlid(uid);
		if(addToSongListMapper.isExist(lid,songid)==null) {
		    addToSongListMapper.insertToCollectSongList(lid,songid);
		}
	}
	
	public void outToLikeSongList(Object uid,String songid) {
		String lid = addToSongListMapper.selectLikelid(uid);
		addToSongListMapper.deleteFromLikeSongList(lid, songid);
	}

	public void addToSheetsSongList(Object uid,String songListName, String listSelected[]) {
		String lid = addToSongListMapper.selectSheetlid(uid,songListName);
		for(int i=0;i<listSelected.length;i++) {
			if(addToSongListMapper.isExist(lid,listSelected[i])==null) {
				addToSongListMapper.inserToSheetSongList(lid, listSelected[i]);
			}
		}
	}
	
	public void addToSheetSongList(Object uid,String songListName, String mid) {
		String lid = addToSongListMapper.selectSheetlid(uid,songListName);
		if(addToSongListMapper.isExist(lid,mid)==null) {
			addToSongListMapper.inserToSheetSongList(lid, mid);
		}
	}

	public void outToSheetsSongList(Object uid, String songListName, String[] listSelected) {
		String lid = addToSongListMapper.selectSheetlid(uid,songListName);
		for(int i=0;i<listSelected.length;i++) {
			addToSongListMapper.deleteFromLikeSongList(lid, listSelected[i]);
		}
	}
}
